<?php
class Userimages_Model_Insertimage implements Userimages_Model_Mainable{
    
    private $core_controller_notnull;
    private $core_controller_csrf_token;
    
    private $userimages_model_imageupload;
    private $userimages_data_insertimage;
    
    private $excepted_result = 1;
    private $actual_result;
    
    public function main(array $variables = null) {
        $this->core_controller_notnull = new Core_Controller_Notnull;
        $this->core_controller_notnull->main($variables);
        $this->core_controller_csrf_token = new Core_Controller_Tokencheckout;
        $this->core_controller_csrf_token->main($variables['post']);
        
        $this->userimages_model_imageupload = new Userimages_Model_Imageupload();
        $variables['post']['file_name'] = $this->userimages_model_imageupload->main($variables);
        
        $this->userimages_data_insertimage = new Userimages_Data_Insertimage;
        $this->actual_result = $this->userimages_data_insertimage->main($variables);
        //var_dump($variables);
        //die();
        if(
                $this->actual_result == $this->excepted_result
                ){
            header("Location: ".SITE_ROOT."zdjecia-uzytkownika.html");
        }
        else {
            header("Location: ".SITE_ROOT."zdjecia-uzytkownika.html");
        }
    }
    
}
